package com.demo.serviceprovider.controller;

import com.demo.serviceprovider.constant.UserTestInfoConst;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/user")
public class UserInfoController {

    @Value("${spring.application.name}")
    private String name ;
    @GetMapping("/getNameByUserId/{id}")
    public String getNameByUserId(@PathVariable("id")int id, HttpServletRequest request){
        String userNameById = UserTestInfoConst.getUserNameById(id);
        return userNameById+"--查询提供"+name+"："+ request.getServerPort();   // 端口信息 用于相同服务多次部署时的负载均衡测试
    }
}
